CPU 686
BITS 32

%define PIC1_CMD 0x20
%define PIC2_CMD 0xA0
%define EOI 0x20
%define DATA_REG 0x60

global _kbd_isr_q
global _lock_kbd_isr_q

global _mouse_isr_q
global _lock_mouse_isr_q

extern _keyboard_queue
extern _mouse_queue
extern _putGQueue
extern _scancode

section .data
mousePacket db 0,0,0
mouseByteIndex dd 1

section .text
_kbd_isr_q:
	push eax
	xor eax, eax
	in al, DATA_REG
	mov byte[_scancode], al
  push _scancode
	push dword[_keyboard_queue]
	call _putGQueue
  add esp, 8
	
	mov al, EOI
	out PIC1_CMD, al
	
	pop eax
  sti
	iretd
_lock_kbd_isr_q:
END

_mouse_isr_q
	push eax
	push ebx
  mov ebx, dword[mouseByteIndex]
  xor eax, eax	
	in al, DATA_REG
	
	cmp ebx, 2
	je byte2
	cmp ebx, 3
	je byte3

byte1:
  mov byte[mousePacket], al
  mov ebx, 2
	jmp fim
byte2:
  mov byte[mousePacket + 1], al
  mov ebx, 3
	jmp fim
byte3:
	mov byte[mousePacket + 2], al
  push mousePacket
  push dword[_mouse_queue]
  call _putGQueue
  add esp, 8
  mov ebx, 1

fim:	
	mov dword[mouseByteIndex], ebx
  mov al, EOI
	out PIC2_CMD, al
	out PIC1_CMD, al
	pop ebx
	pop eax
	iretd
_lock_mouse_isr_q:	
END

